/*
 * Copyright 2009-2017 Alibaba Cloud All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <alibabacloud/sas/model/DescribeBackupFilesResult.h>
#include <json/json.h>

using namespace AlibabaCloud::Sas;
using namespace AlibabaCloud::Sas::Model;

DescribeBackupFilesResult::DescribeBackupFilesResult() :
	ServiceResult()
{}

DescribeBackupFilesResult::DescribeBackupFilesResult(const std::string &payload) :
	ServiceResult()
{
	parse(payload);
}

DescribeBackupFilesResult::~DescribeBackupFilesResult()
{}

void DescribeBackupFilesResult::parse(const std::string &payload)
{
	Json::Reader reader;
	Json::Value value;
	reader.parse(payload, value);
	setRequestId(value["RequestId"].asString());
	auto allBackupFilesNode = value["BackupFiles"]["BrowseFile"];
	for (auto valueBackupFilesBrowseFile : allBackupFilesNode)
	{
		BrowseFile backupFilesObject;
		if(!valueBackupFilesBrowseFile["Name"].isNull())
			backupFilesObject.name = valueBackupFilesBrowseFile["Name"].asString();
		if(!valueBackupFilesBrowseFile["Type"].isNull())
			backupFilesObject.type = valueBackupFilesBrowseFile["Type"].asString();
		if(!valueBackupFilesBrowseFile["Subtree"].isNull())
			backupFilesObject.subtree = valueBackupFilesBrowseFile["Subtree"].asString();
		if(!valueBackupFilesBrowseFile["Size"].isNull())
			backupFilesObject.size = std::stol(valueBackupFilesBrowseFile["Size"].asString());
		backupFiles_.push_back(backupFilesObject);
	}
	auto pageInfoNode = value["PageInfo"];
	if(!pageInfoNode["Count"].isNull())
		pageInfo_.count = std::stoi(pageInfoNode["Count"].asString());
	if(!pageInfoNode["PageSize"].isNull())
		pageInfo_.pageSize = std::stoi(pageInfoNode["PageSize"].asString());
	if(!pageInfoNode["TotalCount"].isNull())
		pageInfo_.totalCount = std::stoi(pageInfoNode["TotalCount"].asString());
	if(!pageInfoNode["CurrentPage"].isNull())
		pageInfo_.currentPage = std::stoi(pageInfoNode["CurrentPage"].asString());

}

DescribeBackupFilesResult::PageInfo DescribeBackupFilesResult::getPageInfo()const
{
	return pageInfo_;
}

std::vector<DescribeBackupFilesResult::BrowseFile> DescribeBackupFilesResult::getBackupFiles()const
{
	return backupFiles_;
}

